package com.bw.session.controller;

import com.bw.common.result.Result;
import com.bw.session.domain.Equipment;
import com.bw.session.domain.Scheduled;
import com.bw.session.domain.dto.SessionDTO;
import com.bw.session.domain.po.BuildingsPO;
import com.bw.session.domain.po.RegionPO;
import com.bw.session.domain.vo.BuildingsVO;
import com.bw.session.domain.vo.RegionVO;
import com.bw.session.domain.vo.SessionVO;
import com.bw.session.service.SessionService;
import com.bw.session.utils.OssUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("session")
@CrossOrigin
public class SessionController {

    @Autowired
    private SessionService sessionService;
    @Autowired
    private OssUtil ossUtil;

    @PostMapping("/getAllSession")
    public Result getAllSession(@RequestBody SessionDTO sessionDTO){
        List<SessionVO> sessionAll = sessionService.getSessionAll(sessionDTO.getSessionName());
        return Result.success(sessionAll);
    }

    @PostMapping("/insertSession")
    public Result insertSession(@RequestBody SessionDTO sessionDTO){
        sessionService.insertSession(sessionDTO);
        return Result.success();
    }

    @PostMapping("upload")
    public Result upload(MultipartFile file){
        String s = ossUtil.uploadMultipartFile(file);
        return Result.success(s);
    }

    @GetMapping("/selectBuildingsInfo")
    public Result selectBuildingsInfo(){
        List<BuildingsVO> buildingsPOS = sessionService.selectBuildingsInfo();
        return Result.success(buildingsPOS);
    }

    @GetMapping("/selectBuildingsInfo/{buildingsId}")
    public Result selectBuildingsInfo(@PathVariable Long buildingsId){
        List<RegionVO> regionPOS = sessionService.selectRegionByBuildingsId(buildingsId);
        return Result.success(regionPOS);
    }

    @GetMapping("/selectAllEquipment")
    public Result selectAllEquipment(){
        List<Equipment> equipment = sessionService.selectAllEquipment();
        return Result.success(equipment);
    }

    @GetMapping("/selectSessionById/{id}")
    public Result<SessionVO> selectSessionById(@PathVariable Long id){
        SessionVO sessionVO = sessionService.selectSessionById(id);
        return Result.success(sessionVO);
    }

    @PutMapping("/update")
    public Result update(@RequestBody SessionDTO sessionDTO){
        sessionService.update(sessionDTO);
        return Result.success();
    }

    @PostMapping("/selectSessionByBuildingsId")
    public Result selectSessionByBuildingsId(@RequestBody SessionVO sessionVO){
        PageInfo<SessionVO> sessionVOPageInfo = sessionService.selectSessionByBuildingsId(sessionVO);
        return Result.success(sessionVOPageInfo);
    }

    @GetMapping("/selectScheduledInfo")
    public Result selectScheduledInfo(@RequestBody Scheduled scheduled){
        List<Scheduled> scheduleds = sessionService.selectScheduledInfo(scheduled);
        return Result.success(scheduleds);
    }

}
